<?php

namespace App\Transformers\Admin;

use League\Fractal\TransformerAbstract;

class CategoryGroupTransformer extends TransformerAbstract
{
    public $availableIncludes = ['category'];

    public function transform($category_group)
    {
        return [
            'id' => $category_group->id,
            'name' => $category_group->name,
            'flag' => $category_group->flag,
        ];
    }

    public function includeCategory($category_group)
    {
        $category = $category_group->category()->where('pid',0)->get();

        return $this->collection($category,new CategoryTransformer());
    }
}

